home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / ham / cat990.zip / FT990.C < prev    next >
C/C++ Source or Header  |  1993-02-01  |  35KB  |  1,547 lines

  1. /******************************************************************************              
  2. *        FT990.C                                  * 
  3. *                                          * 
  4. * 1. Computer Aided Transceiver sytem for the Yaesu FT-990 (Primary)          * 
  5. *                                          * 
  6. * 2. Some of the main commands are identical for the FT-1000, FT-890          * 
  7. *                                          * 
  8. * This is just a template program to test the CAT interface              * 
  9. * on the FT-1000 ,FT-990, and FT-890                          * 
  10. *                                          * 
  11. * This source (FT990.C and FT990.H) is in the public domain              * 
  12. * and may be freely copied                              * 
  13. *                                          * 
  14. * I do request any enhancements made to the program be made              * 
  15. * available to the general ham community too, so that others              * 
  16. * can enjoy doing this as much as I did.                      * 
  17. *=============================================================================+
  18. * and my thanks to:                                  * 
  19. *             C. Karcher                              * 
  20. *                  Seattle WA                              * 
  21. *                  CSID 76406,536                          * 
  22. *                                          * 
  23. * for providing the serial communications utility.                  * 
  24. *        (RS232.C,RS232.H)                          * 
  25. *=============================================================================+ 
  26. *                                          * 
  27. * Any questions or ideas for ft990.c should be addressed to the              * 
  28. * author:                                      * 
  29. *                                          * 
  30. *    Robert Cartier                                  * 
  31. *    112 Fieldbrook Rd.                              * 
  32. *    Middletown, Ct. 06457                              * 
  33. *    (203)771-7027 (Days)                              * 
  34. *       (203)632-9055 (Evenings)                          * 
  35. *    Compuserve : (76424,176)                          * 
  36. *    Packet     : KD1JG @ W1NRG.CT.USA                      * 
  37. *                                          * 
  38. *    Source was compiled using Borland Turbo C++ 1.0                  * 
  39. *                                          * 
  40. *    Date        Version                              * 
  41. *    --------    -------                              * 
  42. *    12/11/92    1.10    Released to the public domain by* Author      * 
  43. *                                                                             *
  44. *     12/16/92    1.20    Completed the Read Meter, Read Flags and      *
  45. *                Read Status.                                  *
  46. *                                                                             *
  47. *    12/17/92    1.21    Added Memory status option              * 
  48. ******************************************************************************/
  49. #include <conio.h>                        
  50. #include <ctype.h>                        
  51. #include <dir.h>                        
  52. #include <stdio.h>                        
  53. #include <stdlib.h>
  54. #include <string.h>
  55. #include "ft990.h"
  56. #include "rs232.c"
  57.  
  58. #define OUT_BUFSIZE 16U  /* 16 bytes output  buffer to minimize scan ahead*/
  59. #define IN_BUFSIZE 2048U /* enough for read status */
  60.  
  61. #define ESC 0x1b
  62.  
  63. char *version = "1.21";
  64. char *date    = "12-17-92";
  65.  
  66. static char in_buf[IN_BUFSIZE];
  67. static char out_buf[OUT_BUFSIZE];
  68.  
  69. int Convert_to_BCD(char *);
  70.  
  71. void Press_Rtn(void);
  72. void Read_5_Bytes(void);
  73. void Flush_Inbuffer(void);
  74. void Toggle_Value(int);
  75. void ScanDir(void);
  76.  
  77. void Read_Status(void);
  78. void Send_To_Radio(void);
  79. void Set_Freq(void);
  80. void Set_Up(char *, char *);
  81. void Toggle_Split_Vfo(void);
  82. void Recall_Mem(void);
  83. void Vfo_Mem(void);
  84. void Lock_Dial(void);
  85. void Toggle_Vfo(void);
  86. void Copy_Vfo_Mem(void);
  87. void Up_Down_Freq(void);
  88. void Scan(void);
  89. void Clarifier(void);
  90. void Set_Modes(void);
  91. void Set_Pacing(void);
  92. void Ptt(void);
  93. void Status_Update(void);
  94. void Tuner_Toggle(void);
  95. void Start_Tuner(void);
  96. void Rpt_Shift_Offset(void);
  97. void Vfo_A_B(void);
  98. void Bandwidth(void);
  99. void Mem_Scan_Skip(void);
  100. int  Step_Freq(void);
  101. void Read_Meter(void);
  102. void Dim_Level(void);
  103. void Read_Flags(void);
  104. void Update_Radio(void);
  105. void Scan_File(void);
  106. void Get_Mode(int);
  107. void Get_Filter(char *,int);
  108. void Disp_Mem(void);
  109.  
  110. void main()
  111. {
  112.     char answer[3] = {'\0'};
  113.     clrscr();
  114.  
  115.     Set_Up(in_buf,out_buf);    /*    initialize I/O port */
  116.  
  117.     for(;;)    {
  118.        clrscr();
  119.      puts("                   ╔════════════════════════════════════╗");
  120.      puts("                   ║ Computer Aided Transceiver Control ║");
  121.      puts("                   ║             for the                ║");
  122.      puts("                   ║           YAESU FT-990             ║");
  123.      puts("                   ║         with support for           ║");
  124.      puts("                   ║           FT-1000/890              ║"); 
  125.      puts("                   ║              KD1JG                 ║");
  126.      puts("                   ╚════════════════════════════════════╝");
  127.      puts("                               ┌───────────┐");
  128.      puts("                               │ Main Menu │");
  129.      puts("                               └───────────┘\n");
  130.      puts("    1. Set New Frequency    2. Recall Memory        3. Copy VFO->M ");
  131.      puts("    4. Lock/Unlock Dial     5. Select VFO           6. Copy M->VFO");
  132.      puts("    7. Step UP/DOWN         8. SCAN                 9. Set Clarifier");
  133.      puts("   10. Split VFO           11. Select Mode         12. Set Pacing ");
  134.      puts("   13. Ptt                 14. Get Radio Status    15. Activate Tuner");
  135.      puts("   16. Start Tuner         17. Rptr Shift/Offset   18. Copy VFO A<->B");
  136.      puts("   19. Select Bandwidth    20. Memory Chan skip    21. Step OP freq");
  137.      puts("   22. Read Meter          23. Dim Level           24. Read Flags");
  138.      puts("   25. Display Memory      26. Update from file    27. Scan From File");
  139.      puts("");
  140.      puts("                           99. Exit");
  141.      gotoxy(1,1);
  142.      printf("Ver. %s",version);
  143.      gotoxy(72,1);
  144.      printf("%s",date);
  145.      fflush(stdin);
  146.      gotoxy(1,25);
  147.      printf("Choice »   ");
  148.      gets(answer);
  149.  
  150.      clrscr();
  151.  
  152.      switch(atoi(answer)) {
  153.           case 1:
  154.         Set_Freq();
  155.         break;
  156.        case 2:
  157.         Recall_Mem();
  158.         break;
  159.        case 3:
  160.         Vfo_Mem();
  161.         break;
  162.        case 4:
  163.         Lock_Dial();
  164.         break;
  165.        case 5:
  166.         Toggle_Vfo();
  167.         break;
  168.        case 6:
  169.         Copy_Vfo_Mem();
  170.         break;
  171.        case 7:
  172.         Up_Down_Freq();
  173.         break;
  174.        case 8:
  175.         Scan();
  176.         break;
  177.        case 9:
  178.         Clarifier();
  179.         break;
  180.        case 10:
  181.         Toggle_Split_Vfo();
  182.         break;
  183.        case 11:
  184.         Set_Modes();
  185.         break;
  186.        case 12:
  187.         Set_Pacing();
  188.         break;
  189.        case 13:
  190.         Ptt();
  191.         break;
  192.        case 14:
  193.         Status_Update();
  194.         break;
  195.        case 15:
  196.         Tuner_Toggle();
  197.         break;
  198.        case 16:
  199.         Start_Tuner();
  200.         break;
  201.        case 17:
  202.         Rpt_Shift_Offset();
  203.         break;
  204.        case 18:
  205.         Vfo_A_B();
  206.         break;
  207.        case 19:
  208.         Bandwidth();
  209.         break;
  210.        case 20:
  211.         Mem_Scan_Skip();
  212.         break;
  213.        case 21:
  214.         Step_Freq();
  215.         break;
  216.        case 22:
  217.         Read_Meter();
  218.         break;
  219.        case 23:
  220.         Dim_Level();
  221.         break;
  222.        case 24:
  223.         Read_Flags();
  224.         break;
  225.        case 25:
  226.         Disp_Mem();
  227.         break;
  228.        case 26:
  229.         Update_Radio();
  230.         break;
  231.        case 27:
  232.         Scan_File();
  233.         break;
  234.        case 99:
  235.         rs_close();
  236.         clrscr();
  237.         puts("Robert Cartier - KD1JG ");
  238.         puts("Packet: KD1JG @ W1NRG.CT");
  239.         puts("CIS:    76424,176");
  240.         sleep(2);
  241.         exit(0);
  242.      }
  243.     }
  244. }
  245. void Set_Freq(void)
  246. {
  247.     int    i,j;
  248.  
  249.     double real_freq = 0;
  250.     double freq_khz = 0;
  251.  
  252.     char freq_out[20];
  253.     char freq_str[20];
  254.  
  255.     send.cmd.opcode = SET_FREQ;        
  256. enter_frq:
  257.     printf("Enter New Frequency : ");
  258.     scanf("%lf",&real_freq);
  259.  
  260.     freq_khz = real_freq * 100000.0;
  261.  
  262.     if ((freq_khz > 2999999) || (freq_khz < 100)){
  263.         printf("out of range -- re-enter\n\a");
  264.         goto enter_frq;
  265.     }
  266.     printf("Real Freq in khz : %08.0f\n",freq_khz);
  267.  
  268.     sprintf(freq_str,"%08.0f",freq_khz);
  269.  
  270.     for(i = 0, j = 0; i < 8 ; i += 2,j++)    
  271.      send.cmd.data[j] = Convert_to_BCD(&freq_str[i]);
  272.  
  273.     Send_To_Radio();
  274. }
  275.  
  276. int Convert_to_BCD(char *tmp)
  277. {
  278.     int bcd;
  279.     char high[2];
  280.     char low[2];
  281.     
  282.     strncpy(high,&tmp[0],1);
  283.     high[1] = '\0';
  284.     strncpy(low,&tmp[1],1);
  285.     low[1] = '\0';
  286.  
  287.     bcd = atoi(low);
  288.  
  289.     bcd += (atoi(high) * 16);
  290.  
  291.     return(bcd);
  292. }
  293.  
  294. void Set_Up(char *in_buf,char *out_buf)
  295. {
  296.  
  297.   char port,parity,bits,stop;
  298.   char tmp[2];
  299.   long baud;
  300.  
  301.   *tmp = '\0';
  302.   while(*tmp < '1' || *tmp > '4') {
  303.     printf("Communications Port (1,2,3 or 4):");
  304.     gets(tmp);
  305.   }
  306.   port = *tmp;
  307.   baud = 4800L;
  308.   parity = 'N';
  309.   bits = '8';
  310.   stop = '2';
  311.  
  312.   /* initialize port */
  313.   if(rs_initport(port,baud,parity,bits,stop,IN_BUFSIZE,in_buf,OUT_BUFSIZE,out_buf)) {
  314.     printf("Failed to initialize port\n");
  315.     rs_close();
  316.     exit(1);
  317.   }
  318. }
  319.  
  320. void Send_To_Radio(void)
  321.     short i = COMMAND_SIZE; /* init to size of command */
  322.  
  323.     Flush_Inbuffer();       /* flush input buffer */
  324.  
  325.     /* send data to radio in reverse order */
  326.  
  327.     do {
  328.       rs_sndbyt(send.cmd_fill.fill[i-1]);
  329.       i--;
  330.     }while(i != 0);
  331.  
  332.     memset(&send,0x00,COMMAND_SIZE);
  333.  
  334.     return;
  335. }
  336. void Toggle_Split_Vfo(void)
  337. {
  338.     Toggle_Value(SPLIT);
  339. }
  340. void Recall_Mem(void)
  341. {
  342.     char ch_str[3];
  343.     char answer[2];
  344.  
  345.     short channel = 0;
  346.  
  347.     printf("Enter Channel to Recall : ");
  348.     scanf("%s",ch_str);
  349.     channel = atoi(ch_str);
  350.     if(channel > 90) {
  351.         printf("\aMust between 0 and 90");
  352.         return;
  353.     }
  354.     send.cmd.opcode  = RECALL_MEM;
  355.     send.cmd.data[0] = channel;
  356.     Send_To_Radio();
  357.  
  358.  
  359. }
  360. void Vfo_Mem(void)
  361. {
  362.     char ch_str[3];
  363.     char answer[2];
  364.  
  365.     short hide = 0;
  366.     short channel = 0;
  367.  
  368.     printf("Enter Channel to Store : ");
  369.     scanf("%s",ch_str);
  370.     channel = atoi(ch_str);
  371.     if((channel < 1) || (channel > 90)) {
  372.         printf("\aMust between 1 and 90");
  373.         return;
  374.     }
  375.     printf("Channel Selected : %s\n",ch_str);
  376.     printf("okay to update (y/n) : ");
  377.     scanf("%s",answer);
  378.  
  379.     if((toupper(*answer)) == 'Y') {
  380.         send.cmd.opcode  = VFO_M;
  381.         send.cmd.data[0] = channel;
  382.         send.cmd.data[1] = hide;
  383.  
  384.         Send_To_Radio();
  385.     }
  386.  
  387. }
  388. void Lock_Dial(void)
  389. {
  390.     Toggle_Value(LOCK_DIAL);
  391.  
  392. }
  393. void Toggle_Vfo(void)
  394. {
  395.     short flag = 1;
  396.     printf("Press any key to toggle <ESC> to exit\n ");
  397.     for(;;) {
  398.      if(kbhit()) {
  399.        if((getch()) == 0x1b)
  400.            break;
  401.        else {
  402.         gotoxy(35,12);
  403.         if( flag){
  404.             puts("VFO A");
  405.             send.cmd.data[0] = OFF;
  406.             flag = FALSE;
  407.         }
  408.         else{
  409.             puts("VFO B"); 
  410.             send.cmd.data[0] = ON;
  411.             flag = TRUE;
  412.         }
  413.                 send.cmd.opcode  = SELECT_VFO;
  414.         Send_To_Radio();
  415.        }
  416.      }
  417.     }
  418. }
  419. void Copy_Vfo_Mem(void)
  420. {
  421.     char ch_str[3];
  422.     char answer[2];
  423.  
  424.     short channel = 0;
  425.  
  426.     printf("Enter Channel to Copy : ");
  427.     scanf("%s",ch_str);
  428.     channel = atoi(ch_str);
  429.     if(channel > 90) {
  430.         printf("\aMust between 0 and 90");
  431.         return;
  432.     }
  433.     send.cmd.opcode  = M_VFO;
  434.     send.cmd.data[0] = channel;
  435.     Send_To_Radio();
  436.  
  437.  
  438. }
  439. void Up_Down_Freq(void)
  440. {
  441.     unsigned char c;
  442.     unsigned short step =0;
  443.     printf("Enter (1) for 1 MHZ or (0) 100 KHZ : ");
  444.     scanf("%d",&step);
  445.  
  446.     send.cmd.data[1] = step;
  447.  
  448.     puts("Enter <ESC> to quit or '+' or '-'");
  449.  
  450.     for(;;) {
  451.      if(kbhit()) {
  452.         gotoxy(35,12);
  453.        switch(getch()) {
  454.           case 0x1b : return;
  455.           case '+'  : 
  456.         puts("UP  ");
  457.         send.cmd.data[1] = step;
  458.         send.cmd.opcode  = UP;
  459.         break;              
  460.           case '-'  : 
  461.         puts("DOWN");
  462.         send.cmd.data[1] = step;
  463.         send.cmd.opcode  = DOWN;
  464.         break;              
  465.        }
  466.        Send_To_Radio();
  467.      }
  468.         }
  469.  
  470. }
  471. void Scan(void)
  472. {
  473.     int    c,i,j;
  474.     int    delay_time = 0;
  475.     int     step_counter = 0;
  476.  
  477.     double freq = 0;
  478.     double start_freq = 0;
  479.     double start_khz = 0;
  480.     double end_freq = 0;
  481.     double end_khz = 0;
  482.  
  483.     char freq_out[20];
  484.     char freq_str[20];
  485.  
  486.  
  487. start:
  488.     printf("Enter New Frequency in Mhz: ");
  489.     scanf("%lf",&start_freq);
  490.  
  491. end:
  492.     printf("Enter END Frequency in Mhz: ");
  493.     scanf("%lf",&end_freq);
  494.  
  495.  
  496.     start_khz = start_freq * 100000.0;
  497.     end_khz = end_freq * 100000.0;
  498.  
  499.     printf("Delay (tenths): ");
  500.     scanf("%d",&delay_time);
  501.  
  502.     if ((start_khz > 2999999) || (start_khz < 100)){
  503.         printf("out of range -- re-enter\n\a");
  504.         goto start;
  505.     }
  506.     if ((end_khz > 2999999) || (end_khz < 100)){
  507.         printf("out of range -- re-enter\n\a");
  508.         goto end;
  509.     }
  510.     sprintf(freq_str,"%08.0f",start_khz);
  511.  
  512.     for(i = 0, j = 0; i < 8 ; i += 2,j++)
  513.         send.cmd.data[j] = Convert_to_BCD(&freq_str[i]);
  514.  
  515.     send.cmd.opcode = SET_FREQ;        
  516.  
  517.     Send_To_Radio();
  518.  
  519.     Set_Modes();
  520.  
  521.     clrscr();
  522.  
  523.         gotoxy(20,20);
  524.     puts("Press any key to stop scanning");
  525.  
  526.     for(freq = start_khz; freq < end_khz + 1.0 ; freq++){
  527.  
  528.  
  529.       if (kbhit()){
  530.         step_counter = Step_Freq();
  531.         freq = freq + step_counter; 
  532.         gotoxy(20,20);
  533.         clreol();
  534.         printf("Press any key to continue scan or <ESC> to exit");
  535.  
  536.          while (!kbhit());
  537.         c = getch();
  538.         if (c == ESC)
  539.             break;
  540.  
  541.         gotoxy(20,20);
  542.         clreol();
  543.             gotoxy(20,20);
  544.         puts("Press any key to stop scanning");
  545.       }
  546.       delay(delay_time * 100); 
  547.       gotoxy(35,12);
  548.       printf("%2.5f",(freq) / 100000.00);
  549.  
  550.       send.cmd.opcode = STEP_FREQ;
  551.       Send_To_Radio();
  552.  
  553.     /* start over  */
  554.  
  555.       if (freq == end_khz  )
  556.       {
  557.  
  558.         sprintf(freq_str,"%08.0f",start_khz);
  559.       
  560.        for(i = 0, j = 0; i < 8 ; i += 2,j++)    
  561.         send.cmd.data[j] = Convert_to_BCD(&freq_str[i]);
  562.  
  563.        send.cmd.opcode = SET_FREQ;
  564.  
  565.        Send_To_Radio();
  566.  
  567.        freq = start_khz;
  568.  
  569.       }
  570.     }    
  571. }
  572.  
  573. void Clarifier(void)
  574. {
  575.     puts("Not completed sorry...");
  576.     sleep(5);    
  577. }
  578. void Set_Modes(void)
  579. {
  580.     char answer[3];    
  581.     int mode = 0;
  582.  
  583.     do{
  584.      clrscr();
  585.      fflush(stdin);
  586.      printf("Enter Mode\n\n");
  587.      printf("\t 0.  LSB\n");
  588.      printf("\t 1.  USB\n");
  589.      printf("\t 2.  CW 2.4k\n");
  590.      printf("\t 3.  CW 500\n");
  591.      printf("\t 4.  AM 6k\n");
  592.      printf("\t 5.  AM 2.4k\n");
  593.      printf("\t 6.  FM\n");
  594.      printf("\t 8.  RTTY (LSB) FT-990\n");
  595.      printf("\t 9.  RTTY (USB) FT-990\n");
  596.      printf("\t10.  PKT (LSB)  FT-990\n");
  597.      printf("\t11.  PKT (FM)   FT-990\n");
  598.      printf("\t12.  Exit\n");
  599.      printf("\nChoice : ");
  600.      gets(answer); 
  601.      mode = atoi(answer); 
  602.  
  603.      if(mode > 12) {
  604.         printf("\aMust between 0 and 11");
  605.         delay(2000);
  606.         continue;
  607.      }
  608.      send.cmd.opcode  = SET_MODE;
  609.      send.cmd.data[0] = mode;
  610.      Send_To_Radio();
  611.     }while(mode != 12);
  612.     
  613. }
  614. void Set_Pacing(void)
  615. {
  616.     unsigned short delay = 0;
  617.     unsigned char answer[2];
  618.  
  619.     printf("Enter Pacing delay in Milliseconds : ");
  620.     scanf("%d",&delay);
  621.  
  622.     if((delay > 255)) {
  623.         printf("\aMust between less than 255");
  624.         return;
  625.     }
  626.     printf("Pacing Delay : %d\n",delay);
  627.     printf("okay to set (y/n) : ");
  628.     scanf("%s",answer);
  629.  
  630.     if((toupper(*answer)) == 'Y') {
  631.      send.cmd.opcode  = PACING;
  632.      send.cmd.data[0] = delay;
  633.  
  634.      Send_To_Radio();
  635.     }
  636.     
  637. }
  638. void Ptt(void)
  639. {
  640.     Toggle_Value(PTT);
  641. }
  642. void Status_Update(void)
  643. {
  644.     double frequency = 0;
  645.  
  646.     clrscr();
  647.  
  648.     send.cmd.opcode  = UPDATE;
  649.  
  650.     Send_To_Radio();
  651.     
  652.     Read_Status();
  653.  
  654.     clrscr();
  655.  
  656.     gotoxy(1,2);
  657.     printf("Split       : %s",r_update.r_update_data.byte_1.bit_0 == 0 ? "Off":"On");
  658.  
  659.     gotoxy(1,3);
  660.     printf("VFO_B       : %s",r_update.r_update_data.byte_1.bit_1 == 0 ? "Transmit" : "Receive");
  661.  
  662.     gotoxy(1,4);
  663.     printf("Fast Tuning : %s",r_update.r_update_data.byte_1.bit_2 == 0 ? "Deactive" : "Active");
  664.  
  665.     gotoxy(1,5);
  666.     printf("Tuner       : %s",r_update.r_update_data.byte_3.bit_6 == 0 ? "Off" : "On");
  667.  
  668.     gotoxy(1,6);
  669.     printf("Transmision : %s",r_update.r_update_data.byte_1.bit_7 == 0 ? "None" : "In-progress");
  670.  
  671.     gotoxy(56,2);
  672.     printf("Scanning    : %s",r_update.r_update_data.byte_2.bit_2 == 0 ? "None" : "In-progress");
  673.  
  674.     gotoxy(56,3);
  675.     printf("Tuning Knob : %s",r_update.r_update_data.byte_2.bit_3 == 0 ? "Unlocked" : "Locked");
  676.  
  677.     gotoxy(56,4);
  678.     printf("M Tune      : %s",r_update.r_update_data.byte_2.bit_4 == 0 ? "Inactive" : "Active");
  679.  
  680.     gotoxy(56,5);
  681.     printf("Tuner       : %s",r_update.r_update_data.byte_1.bit_4 == 0 ? "Inactive" : "Tuning");
  682.  
  683.     gotoxy(56,6);
  684.     if(r_update.r_update_data.byte_2.bit_5 == TRUE)
  685.         printf("Operation   : VFO");
  686.     else if(r_update.r_update_data.byte_2.bit_6 == TRUE)
  687.         printf("Operation   : MEM");
  688.     else if(r_update.r_update_data.byte_2.bit_7 == TRUE)
  689.         printf("Operation   : GEN");
  690.     else
  691.         printf("Operation   : Unknown");
  692.  
  693.     
  694.     gotoxy(30,8);
  695.     printf("Memory Channel  :  ( %d ) ",
  696.             r_update.r_update_data.mem_ch  + 1 );
  697.  
  698. /********************************************************************/
  699.  
  700.     gotoxy(1,9);
  701.         printf("═══════════════════════════════════════════════════════════════════════════");
  702.     gotoxy(1,11);
  703.     printf("  Current status               VFO A  status              VFO B  status \n");
  704.     printf("  --------------               ---------------            --------------\n\n");
  705.  
  706.     gotoxy(1,13);
  707.     printf("Filter      :  %#04x",r_update.r_update_data.current.bpf);
  708.  
  709.     frequency = frequency + ((double)r_update.r_update_data.current.freq1 * 65536);
  710.     frequency = frequency + ((double)r_update.r_update_data.current.freq2 * 256);
  711.     frequency = frequency + (double)r_update.r_update_data.current.freq3;
  712.  
  713.     gotoxy(1,14);
  714.     printf("Frequency   :  %2.5f",frequency/100000);
  715.  
  716.     gotoxy(1,15);
  717.     Get_Mode(r_update.r_update_data.current.mode);
  718.  
  719.     gotoxy(1,16);
  720.     Get_Filter("Filter      ",r_update.r_update_data.current.filter);
  721.  
  722.     gotoxy(1,17);
  723.     Get_Filter("Last SSB    ",r_update.r_update_data.current.ssb);
  724.  
  725.     gotoxy(1,18);
  726.     Get_Filter("Last CW     ",r_update.r_update_data.current.cw);
  727.  
  728.     gotoxy(1,19);
  729.     Get_Filter("Last RTTY   ",r_update.r_update_data.current.rtty);
  730.  
  731.     gotoxy(1,20);
  732.     Get_Filter("Last PKT    ",r_update.r_update_data.current.pkt);
  733.  
  734.     gotoxy(1,21);
  735.     printf("Skip Status :  %s\n",r_update.r_update_data.current.skip == 1 ? "True":"False");
  736.  
  737. /* VFO_A */
  738.  
  739.     gotoxy(30,13);
  740.     printf("Filter      :  %#04x",r_update.r_update_data.vfo_a.bpf);
  741.  
  742.     frequency = 0;
  743.  
  744.     frequency = frequency + ((double)r_update.r_update_data.vfo_a.freq1 * 65536);
  745.     frequency = frequency + ((double)r_update.r_update_data.vfo_a.freq2 * 256);
  746.     frequency = frequency + (double)r_update.r_update_data.vfo_a.freq3;
  747.  
  748.     gotoxy(30,14);
  749.     printf("Frequency   :  %2.5f",frequency/100000);
  750.  
  751.     gotoxy(30,15);
  752.     Get_Mode(r_update.r_update_data.vfo_a.mode);
  753.  
  754.     gotoxy(30,16);
  755.     Get_Filter("Filter      ",r_update.r_update_data.vfo_a.filter);
  756.  
  757.     gotoxy(30,17);
  758.     Get_Filter("Last SSB    ",r_update.r_update_data.vfo_a.ssb);
  759.  
  760.     gotoxy(30,18);
  761.     Get_Filter("Last CW     ",r_update.r_update_data.vfo_a.cw);
  762.  
  763.     gotoxy(30,19);
  764.     Get_Filter("Last RTTY   ",r_update.r_update_data.vfo_a.rtty);
  765.  
  766.     gotoxy(30,20);
  767.     Get_Filter("Last PKT    ",r_update.r_update_data.vfo_a.pkt);
  768.  
  769.     gotoxy(30,21);
  770.     printf("Skip Status :  %s\n",r_update.r_update_data.vfo_a.skip == 1 ? "True":"False");
  771.  
  772. /* VFO_B */
  773.  
  774.  
  775.  
  776.     gotoxy(58,13);
  777.     printf("Filter      :  %#04x",r_update.r_update_data.vfo_b.bpf);
  778.  
  779.     frequency = 0;
  780.  
  781.     frequency = frequency + ((double)r_update.r_update_data.vfo_b.freq1 * 65536);
  782.     frequency = frequency + ((double)r_update.r_update_data.vfo_b.freq2 * 256);
  783.     frequency = frequency + (double)r_update.r_update_data.vfo_b.freq3;
  784.  
  785.     gotoxy(58,14);
  786.     printf("Frequency   :  %2.5f",frequency/100000);
  787.  
  788.     gotoxy(58,15);
  789.     Get_Mode(r_update.r_update_data.vfo_b.mode);
  790.  
  791.     gotoxy(58,16);
  792.     Get_Filter("Filter      ",r_update.r_update_data.vfo_b.filter);
  793.  
  794.     gotoxy(58,17);
  795.     Get_Filter("Last SSB    ",r_update.r_update_data.vfo_b.ssb);
  796.  
  797.     gotoxy(58,18);
  798.     Get_Filter("Last CW     ",r_update.r_update_data.vfo_b.cw);
  799.  
  800.     gotoxy(58,19);
  801.     Get_Filter("Last RTTY   ",r_update.r_update_data.vfo_b.rtty);
  802.  
  803.     gotoxy(58,20);
  804.     Get_Filter("Last PKT    ",r_update.r_update_data.vfo_b.pkt);
  805.  
  806.     gotoxy(58,21);
  807.     printf("Skip Status :  %s\n",r_update.r_update_data.vfo_b.skip == 1 ? "True":"False");
  808. /********************************************************************/
  809.  
  810.     gotoxy(1,24);
  811.  
  812.  
  813.     Press_Rtn();
  814.  
  815.  
  816. }
  817.  
  818. void Tuner_Toggle(void)
  819. {
  820.     Toggle_Value(ANT_TUNER);
  821. }
  822. void Start_Tuner(void)
  823. {
  824.     send.cmd.opcode  = TUNER_START;
  825.  
  826.     Send_To_Radio();
  827.     
  828. }
  829. void Rpt_Shift_Offset(void)
  830. {
  831.     int i,j;
  832.     double offset = 0;
  833.     char freq_str[9];
  834.     char direction[2];
  835.  
  836.     send.cmd.opcode  = RPT_SHIFT;
  837. shift:
  838.     printf("Enter <ESC> to quit or '+'  '-' or '=' :  ");
  839.     gets(direction);
  840.  
  841.     switch(*direction) {
  842.           case 0x1b : return;
  843.           case '+'  : 
  844.         send.cmd.data[0] = 0x02;
  845.         break;              
  846.           case '-'  : 
  847.         send.cmd.data[0] = 0x01;
  848.         break;              
  849.           case '='  : 
  850.         send.cmd.data[0] = 0x00;
  851.         break;              
  852.           default:
  853.         goto shift;
  854.     }
  855.  
  856.     Send_To_Radio();
  857.      
  858. offset:
  859.     printf("Enter Offset Frequency : ");
  860.     scanf("%lf",&offset);    
  861.  
  862.     if(offset > 19999 ) 
  863.     {
  864.         puts("Offset must be less than 20000 khz");
  865.         goto offset;
  866.     }
  867.  
  868.     sprintf(freq_str,"%06.0f",offset);
  869.  
  870.     send.cmd.data[0]  = 0;    /* pad and set parameter (P1) */
  871.  
  872.     for(i = 0, j = 1; i < 6 ; i += 2,j++)         /* skip parameter P1 */
  873.         send.cmd.data[j] = Convert_to_BCD(&freq_str[i]);
  874.  
  875.     send.cmd.opcode  = RPT_OFFSET;
  876.  
  877.     Send_To_Radio();
  878.  
  879.  
  880. }
  881. void Vfo_A_B(void)
  882. {
  883.     send.cmd.opcode  = A_EQUAL_B;
  884.  
  885.     Send_To_Radio();
  886.     
  887. }
  888. void Bandwidth(void)
  889. {
  890.     char answer[3];    
  891.     short Bandwidth = 0;
  892.  
  893.     printf("Enter Bandwidth\n\n");
  894.     printf("\t 0.  2.4 khz\n");
  895.     printf("\t 1.  2.0 khz\n");
  896.     printf("\t 2.  500 hz\n");
  897.     printf("\t 3.  250 hz\n");
  898.     printf("\nChoice : ");
  899.     scanf("%d",&Bandwidth);
  900.     if(Bandwidth > 3) {
  901.         printf("\aMust between 0 and 3");
  902.         return;
  903.     }
  904.     send.cmd.opcode  = BANDWIDTH;
  905.     send.cmd.data[0] = BANDWIDTH;
  906.     Send_To_Radio();
  907.  
  908.     
  909. }
  910. void Mem_Scan_Skip(void)
  911. {
  912.     char ch_str[3];
  913.     char answer[2];
  914.  
  915.     short hide = 0;
  916.     short channel = 0;
  917.  
  918.     printf("Enter Channel to Change : ");
  919.     scanf("%s",ch_str);
  920.     channel = atoi(ch_str);
  921.     if((channel < 1) || (channel > 90)) {
  922.         printf("\aMust between 1 and 90");
  923.         return;
  924.     }
  925.     printf("Enter (1) to Hide or (0) to Include ");
  926.     scanf("%d",&hide);
  927.  
  928.     printf("Channel Selected : %s ",ch_str);
  929.  
  930.     if (hide)
  931.         printf("Hidden : True\n");        
  932.     else
  933.         printf("Hidden : False\n");    
  934.  
  935.     printf("okay to update (y/n) : ");
  936.     scanf("%s",answer);
  937.  
  938.     if((toupper(*answer)) == 'Y') {
  939.         send.cmd.opcode  = MEMORY_SKIP;
  940.         send.cmd.data[0] = channel;
  941.         send.cmd.data[1] = hide;
  942.  
  943.         Send_To_Radio();
  944.     }
  945.         
  946. }
  947. int Step_Freq(void)
  948. {
  949.     unsigned char c;
  950.     int counter = 0;
  951.  
  952.     clrscr();
  953.  
  954.     puts("Enter <ESC> to quit or '+' or '-'");
  955.  
  956.     for(;;) {
  957.      if(kbhit()) {
  958.         gotoxy(35,12);
  959.        switch(getch()) {
  960.           case 0x1b : 
  961.         clrscr();
  962.         return(counter);
  963.           case '+'  : 
  964.         puts("UP  ");
  965.         send.cmd.opcode  = STEP_FREQ;
  966.         send.cmd.data[0]  = 0;
  967.         counter++;
  968.         break;              
  969.           case '-'  : 
  970.         puts("DOWN");
  971.         send.cmd.opcode  = STEP_FREQ;
  972.         send.cmd.data[0]  = 1;
  973.         counter--;
  974.         break;              
  975.        }
  976.        Send_To_Radio();
  977.      }
  978.         }
  979.  
  980.  
  981. }
  982. void Read_Meter(void)
  983. {
  984.     clrscr();
  985.     puts("Presently under beta test for FT-990");
  986.  
  987.     send.cmd.opcode  = READ_METER;
  988.  
  989.     Send_To_Radio();
  990.     
  991.     Read_5_Bytes();
  992.  
  993.     printf("Meter value is : (%d)\n",rcv_cmd.r_meter.meter1);
  994.  
  995.     if (rcv_cmd.r_meter.meter1 == 0)
  996.         printf("S-Meter reading is S0");
  997.     if (rcv_cmd.r_meter.meter1 > 1 && rcv_cmd.r_meter.meter1 < 10 )
  998.         printf("S-Meter reading is S1");
  999.     if (rcv_cmd.r_meter.meter1 > 10 && rcv_cmd.r_meter.meter1 < 41)
  1000.         printf("S-Meter reading is S3");
  1001.     if (rcv_cmd.r_meter.meter1 > 40 && rcv_cmd.r_meter.meter1 < 71)
  1002.         printf("S-Meter reading is S5");
  1003.     if (rcv_cmd.r_meter.meter1 > 70 && rcv_cmd.r_meter.meter1 < 101)
  1004.         printf("S-Meter reading is S7");
  1005.     if (rcv_cmd.r_meter.meter1 > 100 && rcv_cmd.r_meter.meter1 < 126)
  1006.         printf("S-Meter reading is S9");
  1007.     if (rcv_cmd.r_meter.meter1 > 125 && rcv_cmd.r_meter.meter1 < 146)
  1008.         printf("S-Meter reading is S9 + 10");
  1009.     if (rcv_cmd.r_meter.meter1 > 145 && rcv_cmd.r_meter.meter1 < 166)
  1010.         printf("S-Meter reading is S9 + 20");
  1011.     if (rcv_cmd.r_meter.meter1 > 165 && rcv_cmd.r_meter.meter1 < 186)
  1012.         printf("S-Meter reading is S9 + 30");
  1013.     if (rcv_cmd.r_meter.meter1 > 185 && rcv_cmd.r_meter.meter1 < 206)
  1014.         printf("S-Meter reading is S9 + 40");
  1015.     if (rcv_cmd.r_meter.meter1 > 205 && rcv_cmd.r_meter.meter1 < 231)
  1016.         printf("S-Meter reading is S9 + 50");
  1017.     if (rcv_cmd.r_meter.meter1 > 230 && rcv_cmd.r_meter.meter1 < 251)
  1018.         printf("S-Meter reading is S9 + 50");
  1019.  
  1020.  
  1021.     Press_Rtn();    
  1022.     
  1023. }
  1024. void Dim_Level(void)
  1025. {
  1026.     unsigned short i = 0;
  1027.     printf("Press any key to toggle <ESC> to exit\n ");
  1028.     for(;;) {
  1029.      if(kbhit()) {
  1030.        if((getch()) == 0x1b)
  1031.            break;
  1032.        else {
  1033.         if (i > 0x0d)
  1034.             i = 0;
  1035.            gotoxy(30,12);
  1036.            printf("Dim Value (%-2d)",i);
  1037.         send.cmd.data[0] = i++;
  1038.        }
  1039.            send.cmd.opcode  = DIM_LEVEL;
  1040.        Send_To_Radio();
  1041.      }
  1042.     }
  1043.     
  1044. }
  1045. void Read_Flags(void)
  1046. {
  1047.     clrscr();
  1048.  
  1049.     send.cmd.opcode  = READ_FLAGS;
  1050.  
  1051.     Send_To_Radio();
  1052.     
  1053.     Read_5_Bytes();
  1054.  
  1055. /********Rig type *********/
  1056.     printf("                       Model : ");
  1057.  
  1058.     switch(rcv_cmd.r_flags.rig1)
  1059.     {
  1060.       case 0x10  :    printf("FT-1000\n");     break;
  1061.       case 0x09  :    printf("FT-990\n");    break;
  1062.       case 0x08  :    printf("FT-890\n");    break;
  1063.       default    :    printf("\n");        break;
  1064.     }
  1065.  
  1066.     puts("                       ==============");
  1067.  
  1068. /********Byte 1 ***********/
  1069.  
  1070.     printf("Split       : %s\n",rcv_cmd.r_flags.byte_1.bit_0 == 0 ? "Off":"On");
  1071.     printf("VFO_B       : %s\n",rcv_cmd.r_flags.byte_1.bit_1 == 0 ? "Transmit" : "Receive");
  1072.     printf("Fast Tuning : %s\n",rcv_cmd.r_flags.byte_1.bit_2 == 0 ? "Off" : "On");
  1073.     printf("CAT         : %s\n",rcv_cmd.r_flags.byte_1.bit_3 == 0 ? "Off" : "On");
  1074.     printf("Tuner       : %s\n",rcv_cmd.r_flags.byte_1.bit_4 == 0 ? "Inactive" : "Tuning");
  1075.     printf("Keyboard    : %s\n",rcv_cmd.r_flags.byte_1.bit_5 == 0 ? "Idle" : "In-progress");
  1076.     printf("Current Mem : %s\n",rcv_cmd.r_flags.byte_1.bit_6 == 0 ? "Not Blank" : "Empty");
  1077.     printf("Transmision : %s\n",rcv_cmd.r_flags.byte_1.bit_7 == 0 ? "None" : "In-progress");
  1078.  
  1079. /********Byte 2 ***********/
  1080.  
  1081.     printf("Scan Paused : %s\n",rcv_cmd.r_flags.byte_2.bit_0 == 0 ? "False" : "True");
  1082.     printf("Memory CHK  : %s\n",rcv_cmd.r_flags.byte_2.bit_1 == 0 ? "Off" : "In-progress");
  1083.     printf("Scanning    : %s\n",rcv_cmd.r_flags.byte_2.bit_2 == 0 ? "None" : "In-progress");
  1084.     printf("Tuning Knob : %s\n",rcv_cmd.r_flags.byte_2.bit_3 == 0 ? "Unlocked" : "Locked");
  1085.     printf("M Tune      : %s\n",rcv_cmd.r_flags.byte_2.bit_4 == 0 ? "Inactive" : "Active");
  1086.  
  1087.     printf("Operation   : ");
  1088.  
  1089.     if(rcv_cmd.r_flags.byte_2.bit_5 == TRUE)
  1090.         printf(" VFO ");
  1091.     else if(rcv_cmd.r_flags.byte_2.bit_6 == TRUE)
  1092.         printf(" MEM ");
  1093.     else if(rcv_cmd.r_flags.byte_2.bit_7 == TRUE)
  1094.         printf(" GEN ");
  1095.  
  1096.     printf("\n");
  1097.  
  1098. /********Byte 3 ***********/
  1099.  
  1100.     printf("PTT by CAT  : %s\n",rcv_cmd.r_flags.byte_3.bit_0 == 0 ? "False" : "True");
  1101.     printf("TX inhibit  : %s\n",rcv_cmd.r_flags.byte_3.bit_1 == 0 ? "Off" : "On");
  1102.     printf("Key Timer   : %s\n",rcv_cmd.r_flags.byte_3.bit_2 == 0 ? "Off" : "On");
  1103.     printf("M CHK Timer : %s\n",rcv_cmd.r_flags.byte_3.bit_3 == 0 ? "Off" : "On");
  1104.     printf("PTT Inhibit : %s\n",rcv_cmd.r_flags.byte_3.bit_4 == 0 ? "Off" : "On");
  1105.     printf("TX Monitor  : %s\n",rcv_cmd.r_flags.byte_3.bit_5 == 0 ? "Off" : "On");
  1106.     printf("Tuner       : %s\n",rcv_cmd.r_flags.byte_3.bit_6 == 0 ? "Off" : "On");
  1107.     printf("Spot        : %s",rcv_cmd.r_flags.byte_3.bit_7 == 0 ? "Off" : "On");
  1108.  
  1109.     Press_Rtn();    
  1110.     
  1111. }
  1112. void Press_Rtn(void)
  1113. {
  1114.     printf("\n                         Press any key to Continue"); 
  1115.     while(!kbhit());
  1116.     getch();
  1117. }
  1118. void Read_5_Bytes(void)
  1119. {
  1120.     short i = 0;
  1121.     
  1122.     delay(500); 
  1123.  
  1124. /*    printf("Characters read : %d\n",rs_inrcvd()); */
  1125.  
  1126.     while(rs_inrcvd()) {
  1127.        if (i < 5)
  1128.         rcv_cmd.rcv_data.fill[i++] = rs_getbyt();
  1129.       else
  1130.               rs_getbyt();
  1131.     }
  1132. }
  1133. void Read_Status(void)
  1134. {
  1135.     unsigned int i = 0;
  1136.     
  1137.     printf("Stand-by retrieving information....");
  1138.  
  1139.     delay(4000);
  1140.  
  1141.     clrscr();
  1142.  
  1143. /*    printf("Characters Recvd : %d\n",rs_inrcvd()); */
  1144.  
  1145.     while(rs_inrcvd()) {
  1146.        if (i < UPDATE_DATA_SIZE)
  1147.         r_update.r_update_fill.fill[i++] = rs_getbyt();
  1148.       else
  1149.               rs_getbyt();
  1150.  
  1151.     }
  1152. }
  1153. void Update_Radio()
  1154. {
  1155. FILE *in;
  1156.  
  1157.     int    i,
  1158.         j, 
  1159.         channel,
  1160.         mode;
  1161.     
  1162.     double real_freq = 0;
  1163.     double freq_khz = 0;
  1164.  
  1165.     char freq_out[20];
  1166.     char freq_str[20];
  1167.     char comments[80];
  1168.     char tmp[10];
  1169.  
  1170.     if((in = fopen("MYCONFIG.DAT","r")) == NULL){
  1171.         perror("Error Opening MYCONFIG");
  1172.         Press_Rtn();
  1173.         return;
  1174.     }
  1175.  
  1176. /* put radio into vfo mode */
  1177.  
  1178.     send.cmd.opcode  = SELECT_VFO;
  1179.     Send_To_Radio();
  1180.  
  1181.     while( (fscanf(in,"%d %lf %d %s",&channel,&real_freq,&mode,comments)) !=EOF){
  1182.  
  1183. /* set mode */
  1184.  
  1185.      switch(mode){
  1186.        case 0 :     strcpy(tmp,"LSB");
  1187.             break;
  1188.        case 1 :    strcpy(tmp,"USB");
  1189.             break;
  1190.        case 2 :    strcpy(tmp,"CW 2.4K");
  1191.             break;
  1192.        case 3 :    strcpy(tmp,"CW 500");
  1193.             break;
  1194.        case 4 :    strcpy(tmp,"AM 6K");
  1195.             break;
  1196.        case 5 :    strcpy(tmp,"AM 2.4K");
  1197.             break;
  1198.        case 6 :
  1199.        case 7 :    strcpy(tmp,"FM");
  1200.             break;
  1201.        case 8 :    strcpy(tmp,"RTTY LSB");
  1202.             break;
  1203.        case 9 :    strcpy(tmp,"RTTY USB");
  1204.             break;
  1205.        case 10:     strcpy(tmp,"PKT LSB");
  1206.             break;
  1207.        case 11:    strcpy(tmp,"PKT FM");
  1208.             break;
  1209.        default:    printf("\amode (%d) illegal on Channel entry %d\n",mode,channel);
  1210.             Press_Rtn();
  1211.             return;
  1212.      }
  1213.  
  1214.      send.cmd.opcode  = SET_MODE;
  1215.      send.cmd.data[0] = mode;
  1216.      Send_To_Radio();
  1217.  
  1218. /* Calculate frequency */
  1219.  
  1220.      freq_khz = real_freq * 100000.0;
  1221.  
  1222.      if ((freq_khz > 2999999) || (freq_khz < 100)){
  1223.         printf("(%lf) out of range -- re-enter\n\a",freq_khz);
  1224.         Press_Rtn();
  1225.         return;
  1226.      }
  1227.  
  1228.      sprintf(freq_str,"%08.0f",freq_khz);
  1229.  
  1230.      send.cmd.opcode = SET_FREQ;        
  1231.  
  1232.      for(i = 0, j = 0; i < 8 ; i += 2,j++)    
  1233.       send.cmd.data[j] = Convert_to_BCD(&freq_str[i]);
  1234.  
  1235. /* display update info */
  1236.  
  1237.      printf("Ch : %2d  Freq : %10.5f  Mode : %-8s Desc : %s\n",channel,real_freq,tmp,comments);
  1238.  
  1239. /* update radio's frequency */
  1240.  
  1241.      Send_To_Radio();
  1242.  
  1243. /* store in defined memory */
  1244.  
  1245.      if(channel > 90){
  1246.         printf("\a---> chan (%d) illegal\n",channel);
  1247.         Press_Rtn();
  1248.         return;
  1249.      }
  1250.  
  1251.      send.cmd.opcode  = VFO_M;
  1252.      send.cmd.data[0] = channel;
  1253.      Send_To_Radio();
  1254.  
  1255.         }
  1256.  
  1257.     Press_Rtn();
  1258.         fclose(in);
  1259.  
  1260. }
  1261. void Flush_Inbuffer(void)
  1262. {
  1263.     while(rs_inrcvd())
  1264.         rs_getbyt(); 
  1265. }
  1266. void Scan_File(void)
  1267. {
  1268. FILE *in;
  1269.  
  1270.     int    c= 0,
  1271.         i= 0,
  1272.         j= 0, 
  1273.         l= 0,
  1274.         m= 0,
  1275.         time_delay = 0,    
  1276.         mode[255];
  1277.  
  1278.     int loop =0;
  1279.     double real_freq[255];
  1280.     double freq_khz[255];
  1281.  
  1282.     char freq_out[20];
  1283.     char freq_str[20];
  1284.     char tmp[10];
  1285.     char comments[255][80];
  1286.     char filename[64];
  1287.  
  1288.     printf("Files available for scanning\n");
  1289.     printf("----------------------------\n");
  1290.  
  1291.     ScanDir();
  1292.  
  1293.     printf("\n\nEnter Filename : ");
  1294.     gets(filename);
  1295.  
  1296.     if (*filename == '\0')
  1297.         return;
  1298.  
  1299.     if((in = fopen(filename,"rb")) == NULL){
  1300.         perror("Error Opening specified file");
  1301.         Press_Rtn();
  1302.         return;
  1303.     }
  1304.  
  1305.     printf("Enter scan delay in Seconds : ");
  1306.     scanf("%d",&time_delay);
  1307.     time_delay *=  1000;
  1308.  
  1309. /* put radio into vfo mode */
  1310.  
  1311.     send.cmd.opcode  = SELECT_VFO;
  1312.     Send_To_Radio();
  1313.  
  1314.     while( (fscanf(in,"%lf %d %s",&real_freq[i],&mode[i],comments[i])) !=EOF)
  1315.     {
  1316.         if (i > 255){
  1317.            puts("file has to many entries -- must be less than 256");
  1318.            Press_Rtn();
  1319.            return;
  1320.         }
  1321.         i++;
  1322.     }
  1323.  
  1324.     for(j = 0 ; j < i ; j++)
  1325.         freq_khz[j] = real_freq[j] * 100000.0;
  1326.     
  1327. /* start scanning */
  1328.  
  1329.     clrscr();
  1330.  
  1331.     gotoxy(20,20);
  1332.  
  1333.     puts("Press any key to stop scanning");
  1334.  
  1335.     for(loop = 0 ; loop < j ; loop++){    
  1336.  
  1337.      send.cmd.opcode  = SET_MODE;
  1338.      send.cmd.data[0] = mode[loop];
  1339.      Send_To_Radio();
  1340.  
  1341. /* Calculate frequency */
  1342.  
  1343.      sprintf(freq_str,"%08.0f",freq_khz[loop]);
  1344.  
  1345.      send.cmd.opcode = SET_FREQ;        
  1346.  
  1347.      for(l = 0, m = 0; l < 8 ; l += 2,m++)    
  1348.       send.cmd.data[m] = Convert_to_BCD(&freq_str[l]);
  1349.  
  1350. /* update radio's frequency */
  1351.  
  1352.      gotoxy(20,13);    
  1353.      clreol();
  1354.      printf("Freq %lf  Desc : %s\n",real_freq[loop],comments[loop]);
  1355.  
  1356.      Send_To_Radio();
  1357.  
  1358.      if(loop == j - 1)
  1359.       loop= -1;        /* reset and start over */
  1360.  
  1361.      delay(time_delay);
  1362.  
  1363.      if (kbhit()){
  1364.         gotoxy(20,20);
  1365.         clreol();
  1366.         printf("Press any key to continue scan or <ESC> to exit");
  1367.         c = getch();
  1368.         if (c == ESC)
  1369.             break;
  1370.  
  1371.          while (!kbhit());
  1372.         c = getch();
  1373.         if (c == ESC)
  1374.             break;
  1375.  
  1376.         gotoxy(20,20);
  1377.         clreol();
  1378.      }
  1379.  
  1380.         }
  1381.  
  1382.         fclose(in);
  1383. }
  1384.  
  1385. void Toggle_Value(command)
  1386. {
  1387.     short flag = 0;
  1388.     printf("Press any key to toggle <ESC> to exit\n ");
  1389.     for(;;) {
  1390.      if(kbhit()) {
  1391.        if((getch()) == 0x1b)
  1392.            break;
  1393.        else {
  1394.         gotoxy(35,12);
  1395.         if( flag){
  1396.             puts("OFF");
  1397.             send.cmd.data[0] = OFF;
  1398.             flag = FALSE;
  1399.         }
  1400.         else{
  1401.             puts("ON "); 
  1402.             send.cmd.data[0] = ON;
  1403.             flag = TRUE;
  1404.         }
  1405.                 send.cmd.opcode  = command;
  1406.         Send_To_Radio();
  1407.        }
  1408.      }
  1409.     }
  1410. }
  1411. void ScanDir(void)
  1412. {
  1413.     struct ffblk ffblk;
  1414.  
  1415.     int done=0;
  1416.  
  1417.     done = findfirst("*.dat",&ffblk,0);
  1418.  
  1419.     while(!done)
  1420.     {
  1421.           if(strstr(ffblk.ff_name,"MYCONFIG.DAT") == NULL) 
  1422.             printf("%s\n",ffblk.ff_name);
  1423.           done = findnext(&ffblk);
  1424.  
  1425.     }          
  1426.  
  1427. }
  1428.     
  1429. void Get_Mode(tmp)
  1430. {
  1431.     switch(tmp)
  1432.     {
  1433.         case 0 : printf("Mode        :  LSB");break;
  1434.         case 1 : printf("Mode        :  USB");break;
  1435.         case 2 : printf("Mode        :  CW");break;
  1436.         case 3 : printf("Mode        :  AM");break;
  1437.         case 4 : printf("Mode        :  FM");break;
  1438.         case 5 : printf("Mode        :  RTTY");break;
  1439.         case 6 : printf("Mode        :  PKT");break;
  1440.     }
  1441.  
  1442. }
  1443.  
  1444. void Get_Filter(char *desc,int tmp)
  1445. {
  1446.     switch(tmp)
  1447.     {
  1448.         case 0 : printf("%12s:  2.4k",desc);break;
  1449.         case 1 : printf("%12s:  2.0k",desc);break;
  1450.         case 2 : printf("%12s:  500",desc);break;
  1451.         case 3 : printf("%12s:  250",desc);break;
  1452.         case 4 : printf("%12s:  6k",desc);break;
  1453.         default: printf("%12s:  UNKNOWN",desc);break;
  1454.     }
  1455. }
  1456. void Disp_Mem(void)
  1457. {
  1458.  
  1459. #define    MEM_OFFSET    36    /* starting position of VFO_B */
  1460.  
  1461. /*    struct BYTE_16 memory_channel; */
  1462.  
  1463.     struct BYTE_16 *memptr;
  1464.  
  1465.     int offset = 0;
  1466.     int channel = 0;
  1467.  
  1468.     double frequency = 0;
  1469.  
  1470.     clrscr();
  1471.  
  1472. channel:
  1473.     printf("Enter Memory Channel to review : ");
  1474.     scanf("%d",&channel);
  1475.  
  1476.     if ( (channel == 0) || (channel > 90) )
  1477.     {
  1478.         printf("out-of-range\n");
  1479.         sleep(2);    
  1480.         goto channel;
  1481.     }
  1482.  
  1483.     send.cmd.opcode  = UPDATE;
  1484.  
  1485.     Send_To_Radio();
  1486.     
  1487.     Read_Status();
  1488.  
  1489.     clrscr();
  1490.  
  1491.     offset = MEM_OFFSET + (channel  * 16); 
  1492.     
  1493. /*    memcpy(&memory_channel , &r_update.r_update_fill.fill[offset] , 16); */
  1494.  
  1495.     memptr = (struct BYTE_16 *)&r_update.r_update_fill.fill[offset];
  1496.  
  1497.     gotoxy(25,3);
  1498.  
  1499.     printf("Memory Channel  :  ( %d ) \n",channel);
  1500.  
  1501. /********************************************************************/
  1502.  
  1503.     gotoxy(28,5);
  1504.     printf("  Current status\n");
  1505.  
  1506.     gotoxy(28,6);
  1507.     printf("  --------------\n");
  1508.  
  1509.     gotoxy(28,8);
  1510.     printf("Filter      :  %#04x\r\n",memptr->bpf);
  1511.  
  1512.  
  1513.     frequency = frequency + ((double)memptr->freq1 * 65536);
  1514.     frequency = frequency + ((double)memptr->freq2 * 256);
  1515.     frequency = frequency + (double)memptr->freq3;
  1516.  
  1517.     gotoxy(28,9);
  1518.     printf("Frequency   :  %2.5f\r\n",frequency/100000);
  1519.  
  1520.     gotoxy(28,10);
  1521.     Get_Mode(memptr->mode);
  1522.  
  1523.     gotoxy(28,11);
  1524.     Get_Filter("Filter      ",memptr->filter);
  1525.  
  1526.     gotoxy(28,12);
  1527.     Get_Filter("Last SSB    ",memptr->ssb);
  1528.  
  1529.     gotoxy(28,13);
  1530.     Get_Filter("Last CW     ",memptr->cw);
  1531.  
  1532.     gotoxy(28,14);
  1533.     Get_Filter("Last RTTY   ",memptr->rtty);
  1534.  
  1535.     gotoxy(28,15);
  1536.     Get_Filter("Last PKT    ",memptr->pkt);
  1537.  
  1538.     gotoxy(28,16);
  1539.     printf("Skip Status :  %s\r\n",memptr->skip == 1 ? "True":"False");
  1540.  
  1541.     gotoxy(1,24);
  1542.  
  1543.  
  1544.     Press_Rtn();
  1545.  
  1546. }